<template>
	<view>
		<view class="goods-item">
			<view class="goods-item-left">
				<radio @click="radioClickHandler" :checked="goods.goods_state" color="#c00000" v-show="showRadio" />
				<image :src="goods.goods_small_logo || defaultPic"></image>
			</view>
			<view class="goods-item-right">
				<text class="goods_name">{{goods.goods_name}}</text>
				<view class="goods-info-box">
					<text class="goods_price">￥{{goods.goods_price | formmatPrice}}</text>
					<uni-number-box v-show="showNumberBox" :min="1" v-model="goods.goods_count" @change="goodsNumberHandler"></uni-number-box>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"goods-item",
		data() {
			return {
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
		props:{
			goods:{
				type:Object,
				default:{}
			},
			showRadio:{
				type:Boolean,
				default:false
			},
			showNumberBox:{
				type:Boolean,
				default:false
			}
		},
		filters:{
			formmatPrice(price){
				return Number(price).toFixed(2);
			}
		},
		methods:{
			radioClickHandler(){
				this.$emit('radio-change', {
					goods_id: this.goods.goods_id,
					goods_state: !this.goods.goods_state
				})
			},
			goodsNumberHandler(number){
				this.$emit('number-change', {
					goods_id:this.goods.goods_id,
					goods_count: +number
				})
			}
		}
	}
</script>

<style lang="scss">
.goods-item{
	display: flex;
	padding: 10px 5px;
	border-bottom: 1px solid #f0f0f0;
	.goods-item-left{
		display: flex;
		align-items: center;
		justify-content: space-between;
		image{
			width:100px;
			height: 100px;
		}
	}
	.goods-item-right{
		flex: 1;
		display: flex;
		margin-left: 5px;
		flex-direction: column;
		justify-content: space-between;
		.goods_name{
			 font-size: 13px;
		}
		.goods-info-box{
			display: flex;
			justify-content: space-between;
			.goods_price{
				color: #c00000;
				font-size: 16px;
			}
		}
	}
}
</style>